<?php

namespace App\Http\Middleware;

use Auth;
use Closure;
use Illuminate\Http\Request;

class checkLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    private $headers = [
        'content-type' => 'application/json'
    ];

    public function handle(Request $request, Closure $next)
    {
        if(Auth::id() == null)
        {
            $response['errorCode'] = config('result.errorNotLoginCode');
            $response['errorMsg']  = config('result.errorNotLoginMsg');
            return response(json_encode($response), 301, $this->headers);
        }
        return $next($request);
    }
}
